package logic

import (
	"context"
	"doctor-medicine-system/mysql/models"

	"doctor-medicine-system/doctorrpc/doctorrpc"
	"doctor-medicine-system/doctorrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
	return &AddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 药品添加
func (l *AddLogic) Add(in *doctorrpc.AddRequest) (*doctorrpc.AddResponse, error) {
	// todo: add your logic here and delete this line

	shop := models.Shop{
		Name:     in.Name,
		Num:      int(in.Num),
		Address:  in.Address,
		Title:    in.Title,
		Fans:     in.Fans,
		DoctorId: in.DoctorId,
	}

	models.DB.Debug().Create(&shop)

	return &doctorrpc.AddResponse{
		ShopId: int64(shop.ID),
	}, nil
}
